package com.guigu.base.service.impl;

import com.guigu.base.entity.CoreOrg;
import com.guigu.base.entity.vo.DashboardVO;
import com.guigu.base.entity.vo.OrderDashboardVO;
import com.guigu.base.feign.OrderFeign;
import com.guigu.base.feign.WorkFeign;
import com.guigu.base.service.CoreOrgService;
import com.guigu.base.service.DashboardService;
import com.guigu.base.service.TransportLineService;
import com.guigu.tms.result.R;
import com.guigu.tms.result.ResultCode;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName:DashboardServiceImpl
 * @Description://TODO
 * @Author:taoLong
 * @Date:2021/12/3:13:49 星期五
 * @email:2391611102@qq.com or 2391611102qq@gmail.com
 */
@Service
public class DashboardServiceImpl implements DashboardService {

    private OrderFeign orderFeign;
    private WorkFeign workFeign;
    private TransportLineService transportLineService;
    private CoreOrgService coreOrgService;


    public DashboardServiceImpl(OrderFeign orderFeign, WorkFeign workFeign, TransportLineService transportLineService, CoreOrgService coreOrgService) {
        this.orderFeign = orderFeign;
        this.workFeign = workFeign;
        this.transportLineService = transportLineService;
        this.coreOrgService = coreOrgService;
    }

    /**
     * 获取基础数据面板
     *
     * @param dateCount 天数
     * @return
     */
    @Override
    public R<DashboardVO> getDashboard(Integer dateCount) {
        DashboardVO dashboardVO = new DashboardVO();
        R<OrderDashboardVO> r = orderFeign.getOrderDashboardData(dateCount);
        if (ObjectUtils.isNotEmpty(r.getData())) {
            dashboardVO.setOrderDashboardVO(r.getData());
        }
        /**
         * 车载状态信息
         */
        dashboardVO.setTruckStatusDashboardVO(workFeign.getTruckStatusCount().getData());
        /**
         * 订单信息
         */
        dashboardVO.setTransportOrderDashboardVO(workFeign.getTransportOrderCount().getData());
        /**
         * 所有线路信息
         */
        dashboardVO.setTransportLineDashboardVOS(transportLineService.getLineDashboard().getData());
        /**
         * 获取所有的机构信息
         */
        List<CoreOrg> orgList = coreOrgService.list(null);
        dashboardVO.setCoreOrgList(orgList);
        return new R<>(ResultCode.SUCCESS_CODE, dashboardVO);
    }
}
